home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
c
/
bbsckit.zip
/
UMODEM.C
< prev
Wrap
Text File
|
1980-01-01
|
45KB
|
1,414 lines
/*
* UMODEM Version 3.7
*
* UMODEM -- Implements the "CP/M User's Group XMODEM" protocol,
* the TERM II File Transfer Protocol (FTP) Number 1,
* and the TERM II File Transfer Protocol Number 4 for
* packetized file up/downloading.
*
* Note: UNIX System-Dependent values are indicated by the string [SD]
* in a comment field on the same line as the values.
*
*
* -- Lauren Weinstein, 6/81
* -- (Version 2.0) Modified for JHU/UNIX by Richard Conn, 8/1/81
* -- Version 2.1 Mods by Richard Conn, 8/2/81
* . File Size Included on Send Option
* -- Version 2.2 Mods by Richard Conn, 8/2/81
* . Log File Generation and Option Incorporated
* -- Version 2.3 Mods by Richard Conn, 8/3/81
* . TERM II FTP 1 Supported
* . Error Log Reports Enhanced
* -- Version 2.4 Mods by Richard Conn, 8/4/81
* . 16K-extent sector number check error corrected
* . Count of number of received sectors added
* -- Version 2.5 Mods by Richard Conn, 8/5/81
* . ARPA Net Flag added
* . ARPA Net parameter ('a') added to command line
* . ARPA Net BIS, BIE, BOS, BOE added
* . ARPA Net FFH escape added
* -- Version 2.6 Mods by Bennett Marks, 8/21/81 (Bucky @ CCA-UNIX)
* . mods for UNIX V7 (Note: for JHU compilation define
* the variable JHU during 'cc'
* . added 'mungmode' flag to protect from inadvertant
* overwrite on file receive
* . changed timeout handling prior to issuing checksum
* -- Version 2.7 Mods by Richard Conn, 8/25/81 (rconn @ BRL)
* . correct minor "ifndef" error in which ifndef had no arg
* . restructured "ifdef" references so that other versions
* of UNIX than Version 7 and JHU can be easily incorporated;
* previous ifdef references were for JHU/not JHU;
* to compile under Version 7 or JHU UNIX, the following
* command lines are recommended:
* "cc umodem.c -o umodem -DVER7" for Version 7
* "cc -7 umodem.c -o umodem -DJHU" for JHU
* . added 'y' file status display option; this option gives
* the user an estimate of the size of the target file to
* send from the UNIX system in terms of CP/M records (128
* bytes) and Kbytes (1024 byte units)
* . added '7' option which modifies the transmission protocols
* for 7 significant bits rather than 8; modifies both FTP 1
* and FTP 3
* -- Version 2.8 Mods by Richard Conn, 8/28/81
* . corrected system-dependent reference to TIOCSSCR (for
* disabling page mode) and created the PAGEMODE flag which
* is to be set to TRUE to enable this
* . added -4 option which engages TERM II, FTP 4 (new release)
* -- Version 2.9 Mods by Richard Conn, 9/1/81
* . internal documentation on ARPA Net protocols expanded
* . possible operator precedence problem with BITMASK corrected
* by redundant parentheses
* -- Version 3.0 Mods by Lauren Weinstein, 9/14/81
* . fixed bug in PAGEMODE defines (removed PAGEMODE define
* line; now should be compiled with "-DPAGEMODE" if
* Page Mode is desired)
* . included forward declaration of ttyname() to avoid problems
* with newer V7 C compilers
* -- Version 3.1 Mods by Lauren Weinstein, 4/17/82
* . avoids sending extraneous last sector when file EOF
* occurs on an exact sector boundary
* -- Version 3.2 Mods by Michael M Rubenstein, 5/26/83
* . fixed bug in readbyte. assumed that int's are ordered
* from low significance to high
* . added LOGDEFAULT define to allow default logging to be
* off. compile with -DLOGDEFAULT=0 to set default to no
* logging.
* -- Version 3.3 Mod by Ben Goldfarb, 07/02/83
* . Corrected problem with above implementation of "LOGDEFAULT".
* A bitwise, instead of a logical negation operator was
* used to complement LOGFLAG when the '-l' command line
* flag was specified. This can cause LOGFLAG to be true
* when it should be false.
* -- Version 3.4 Mods by David F. Hinnant, NCECS, 7/15/83
* . placed log file in HOME directory in case user doesn't
* have write permission in working directory.
* . added DELDEFAULT define to allow default purge/no purge
* of logfile before starting. Compile with -DDELDEFAULT=0
* to set default to NOT delete the log file before starting.
* . check log file for sucessful fopen().
* . buffer disk read for sfile().
* . turn messages off (standard v7) before starting.
* -- Version 3.5 Mods by Richard Conn, 08/27/83
* . added equates for compilation under UNIX SYSTEM III
* to compile for SYSTEM III, use -DSYS3 instead of
* -DJHU or -DVER7
* . added command mode (-c option) for continuous entry
* of commands
* -- Version 3.6 Mods by Ben Goldfarb (ucf-cs!goldfarb), 09/03/83
* . added '#include <ctype.h>' since tolower() is used, but
* is not defined in umodem. This is necessary to compile
* on V7 systems. Also added a isupper() test because
* tolower() in /usr/include/ctype.h doesn't do that.
* . cleaned up all the improper bitwise complementation of
* logical constants and variables.
* -- Version 3.7 Mods by Noel J. Bergman, 02/27/84
* . Corrected problem with ALARM signal in 4.2 BSD Unix.
* BSD Unix restarts system calls after signal is handled,
* so setjmp() and longjmp() are used to handle I/O timeout.
* Since this will work with all Unix systems, and is a lot
* cleaner than depending on side effects, there is no need
* to make this code conditional.
*
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <setjmp.h>
#include <ctype.h>
/* JHU UNIX tty parameter file */
#ifdef JHU
#include <stty.h>
#endif
/* Version 7 UNIX tty parameter file */
#ifdef VER7
#include <sgtty.h>
#endif
/* UNIX SYSTEM III tty parameter file */
#ifdef SYS3
#include <sgtty.h>
#endif
/* log default define */
#ifndef LOGDEFAULT
#define LOGDEFAULT 1
#endif
/* Delete logfile define. Useful on small systems with limited
* filesystem space and careless users.
*/
#ifndef DELDEFAULT
#define DELDEFAULT 1
#endif
#include <signal.h>
#define VERSION 37 /* Version Number */
#define FALSE 0
#define TRUE 1
/* Compile with "-DPAGEMODE" if Page Mode (TIOCSSCR) is supported on your
* UNIX system. If it is supported, make sure that TIOCSSCR is the
* correct name for Page Mode engagement.
*/
/* ASCII Constants */
#define SOH 001
#define STX 002
#define ETX 003
#define EOT 004
#define ENQ 005
#define ACK 006
#define LF 012 /* Unix LF/NL */
#define CR 015
#define NAK 025
#define SYN 026
#define CAN 030
#define ESC 033
#define CTRLZ 032 /* CP/M EOF for text (usually!) */
/* UMODEM Constants */
#define TIMEOUT -1
#define ERRORMAX 10 /* maximum errors tolerated */
#define RETRYMAX 10 /* maximum retries to be made */
#define BBUFSIZ 128 /* buffer size -- do not change! */
/* [SD] Mode for Created Files */
#define CREATMODE 0600 /* mode for created files */
/* ARPA Net Constants */
/* The following constants are used to communicate with the ARPA
* Net SERVER TELNET and TIP programs. These constants are defined
* as follows:
* IAC <-- Is A Command; indicates that
* a command follows
* WILL/WONT <-- Command issued to SERVER TELNET
* (Host); WILL issues command
* and WONT issues negative of
* the command
* DO/DONT <-- Command issued to TIP; DO issues
* command and DONT issues
* negative of the command
* TRBIN <-- Transmit Binary Command
* Examples:
* IAC WILL TRBIN <-- Host is configured to transmit Binary
* IAC WONT TRBIN <-- Host is configured NOT to transmit binary
* IAC DO TRBIN <-- TIP is configu